from django.db import models


# Create your models here.

class UserProfile(models.Model):
    """
    用户表：
    用户名、密码、邮箱、手机号、是否激活、
    注册时间、修改时间
    """
    username = models.CharField(
        max_length=11, verbose_name="用户名",
        unique=True)
    password = models.CharField(
        max_length=32, verbose_name="密码"
    )
    email = models.EmailField()
    phone = models.CharField(max_length=11)
    is_active = models.BooleanField(
        default=False, verbose_name="是否激活")
    # 创建时间 更新时间
    create_time = models.DateTimeField(
        auto_now_add=True)
    update_time = models.DateTimeField(
        auto_now=True
    )

    class Meta:
        # 修改表名：应用名_类名非驼峰
        db_table = "users_user_profile"


class Address(models.Model):
    """
    收货地址表
    """
    user_profile = models.ForeignKey(UserProfile,
                                     on_delete=models.CASCADE)
    # 收件人、地址、邮编、手机号
    receiver = models.CharField(verbose_name='收件人', max_length=20)
    address = models.CharField(verbose_name='收件地址', max_length=100)
    postcode = models.CharField(verbose_name="邮编", max_length=6)
    receiver_mobile = models.CharField(verbose_name="手机号", max_length=11)
    # 标签[家、公司、宿舍]
    tag = models.CharField(verbose_name="标签", max_length=10)
    # 默认地址
    is_default = models.BooleanField(verbose_name="默认地址", default=False)
    # 伪删除 [0-未删除 1-删除]
    is_delete = models.BooleanField(default=False, verbose_name="伪删除")
    # 创建时间 更新时间
    create_time = models.DateTimeField(
        auto_now_add=True)
    update_time = models.DateTimeField(
        auto_now=True
    )

    class Meta:
        # 修改表名：应用名_类名非驼峰
        db_table = "users_address"


class WeiboProfile(models.Model):
    """
    微博表：和用户表一对一关系
    user_profile允许为空
    用户到绑定注册页后直接关闭页面没有执行绑定注册流程
    """
    user_profile = models.OneToOneField(UserProfile, on_delete=models.CASCADE, null=True)
    wuid = models.CharField(max_length=10, unique=True, db_index=True)
    access_token = models.CharField(max_length=32)

    class Meta:
        db_table = "users_weibo_profile"
